/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controller.commands;

import core.BoxNode;
import core.Node;
import java.util.ArrayList;
import model.graphic.objects.GBoxNode;
import model.graphic.objects.GNode;
import model.graphic.objects.Graphical;
import model.graphic.objects.RectangleGraphical;
import view.GUI.LabelReader;

/**
 *
 * @author Jelle
 */
public class DeBoxCommand extends BasicCommand {

    public DeBoxCommand() {
    }

    @Override
    public void execute() {
        RectangleGraphical node = (RectangleGraphical) gmodel.getSelected();
        GBoxNode bn = node.getBoxNode();
        BoxNode cb = (BoxNode) sync.get(bn);
        Node cn = sync.get(node);
        if (GNode.class.isAssignableFrom(node.getClass())) {
            GNode gn = (GNode) node;
            ArrayList<Graphical> arg = bn.getAttachments(gn);
            for (Graphical g : arg) {
                gmodel.addObject(g);
            }
            bn.removeInternalNode(gn);
        } else if (GBoxNode.class.isAssignableFrom(node.getClass())) {
            bn.removeInternalObject(node);
        }

        gmodel.addObject(node);
        System.out.println("S3");
        
        
        node.setBoxNode(null);
        node.setBoxed(false);
        cb.removeNode(cn.getClass().getSimpleName());
        controller.getDebug().append(LabelReader.getInstance().getString("NodeIsNoLongerAddedToBox"));
    }
}
